package com.Maykk.charStream;

import java.io.*;

/**
 * @ClassName: Demo06
 * @Description: TODO FileReader && FileWrite 练习
 * @Author: MaykkStar@163.com
 */
public class Demo06 {
    public static void main(String[] args) throws IOException {
        final String SRC = "./Maykk.txt";
        final String TO = "./MaykkNew.txt";

        // InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(SRC));
        // OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(TO));

        /**
         * InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(SRC));
         *       ## 上下功能一样  ##
         * FileReader fileReader = new FileReader(SRC);
         */


        FileReader fileReader = new FileReader(SRC);
        FileWriter fileWriter = new FileWriter(TO);

        // 一次读写一个字符
        int ch;
        while ((ch = fileReader.read()) != -1) {
            fileWriter.write(ch);
            fileWriter.flush();
        }

        // 一次读写一个字符数组
        char[] chars = new char[1024];
        int len;
        while ((len = fileReader.read(chars)) != -1) {
            fileWriter.write(chars, 0, len);
            fileWriter.flush();
        }


        fileWriter.close();
        fileReader.close();
    }
}
